;(function(){
var role = require("./role");
var BusCon = require("../../core/bus/_con");
var UserCon = require("../../core/user/_con");
var GoodsCon = require("../../core/goods/_con");
var AchCon = require("../../core/ach/_con");
var db = require("../../core/db/index");
var config = require("../../core/_include/config");
var ResponObj = require("../_include/ResponObj");	
module.exports = {
	prefix:"/user/achs",
	get:{
		//获取当前用户的购买历史
		"/":function *(){
			try{
				var user  = role.getUser(this);
			}catch(errorMsg){
				this.body = ResponObj("error",errorMsg);
				return;
			}
			var num = (+this.params.num)||5;
			var achs = user.getAchs(num);
			this.body = ResponObj("json",achs);
		},
		"/detail":function *() {
			try{
				var user  = role.getUser(this);
			}catch(errorMsg){
				this.body = ResponObj("error",errorMsg);
				return;
			}
			var num = (+this.params.num)||5;
			var achs = user.getAchs(num);
			achs.forEach(function(ach_id,index){
				achs[index] = AchCon.get(ach_id);
			});
			this.body = ResponObj("json",achs);
		},
		// "/cancelAch/:ach_id":function * () {
		// 	try{
		// 		var user  = role.getUser(this);
		// 	}catch(errorMsg){
		// 		this.body = ResponObj("error",errorMsg);
		// 		return;
		// 	}
		// 	var ach_id = this.params.ach_id;
		// 	if(user.removeAch(ach_id)){
		// 		this.body = ResponObj("json","已成功取消订单");
		// 	}else{
		// 		this.body = ResponObj("error","找不到指定商品");
		// 	}
		// }
	},
	post:{
		"/":function *(){}
	}
};
}());